@include('admin.layout.bone_header')


<div class="layui-btn-container">
    <button class="layui-btn" data-type="addVip">添加VIP</button>
</div>

<table class="layui-hide" id="think-table" lay-filter="think-table"></table>


<script id="barDemo" type="text/html">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
{{--    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>--}}



</script>

<script>

    layui.use('table', function () {
        let table = layui.table;
        UI.getPageTable(table, "{{route('admin.vip.vips')}}?type=1", [
            {field: 'vip_id', title: 'ID', width:80, sort: true,fixed: 'left'}
            ,{field: 'vip_name',title:'Vip名字'}
            ,{field: 'vip_price',title:'VIP价格'}
            ,{field: 'vip_index',title:'VIP标识'}
            ,{fixed: 'right',title:'操作', align:'center', toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            if(obj.event === 'edit'){
                UI.openLayer("{{route('admin.vip.edit_vip')}}?vip_id="+data['vip_id']);
            }else if(obj.event == 'del'){
                UI.delete(data['vip_id'],function(res){
                    table.reload('think-table');
                },"{{route('admin.vip.del_vip')}}");
            }
        });
        let $ = layui.$, active = {
            addVip:function (){
                UI.openLayer("{{route('admin.vip.add_vip')}}");
            },
            reload:function (){
                let search_key = $('#search_key');
                //执行重载
                table.reload('think-table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        'search_key':search_key.val(),
                    }
                });
            }
        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
